﻿@model Physis.Client.Models.Configuration.RoleModel

@{ Layout = "~/Views/Configuration/ConfigurationItemMaster.cshtml"; }

<script type="text/javascript" src="~/Scripts/Application/Configuration/Role.js"></script>

@section InlineStyles {

    <style type="text/css">

    .PropertyTable td { padding: 8px; }

    .PropertyTable td:first-child { font-weight: bold; }

    </style>       
    
}

@section ItemPropertyTabsContent_GeneralProperties {

    <table class="PropertyTable">
        
        <thead><tr><th style="width: 90px"></th><th></th></tr></thead>
        
            <tr>

                <td>Environment: </td>

                <td>
                    
                    @* CANNOT CHANGE THE ENVIRONMENT ON EXISTING ROLES *@

                    @if ((Model.Role.Id == 0) && (!Model.ForEnteprise)) { 

                        @Html.DropDownList("Role.EnvironmentId", Model.EnvironmentSelectList, new { style="width: 250px;" })

                    }

                    else if (Model.Role.EnvironmentId == 0)  { <span>(Enterprise)</span> }
                        
                    else { 
                    
                        @Html.HiddenFor(model => model.Role.EnvironmentId)
                            
                        @Model.Role.EnvironmentName 
                    
                    }


                    @* THE BELOW ARE HIDDEN TEXT INPUTS FOR SERIALIZING THE GRID DATA BACK TO THE SERVER *@
                    
                    <input id="RolePermissions" name="Role.Permissions" type="hidden" />

                    <input id="RoleMembership" name="Role.Membership" type="hidden" />

                </td>
                    
                <td></td>

            </tr>

        <tr>

    </table>
    
}

@section ItemPropertyTabs {
    
    <li><a href="#PropertyTab_Permissions">Permissions</a></li>

    <li><a href="#PropertyTab_Membership">Membership</a></li>

}

@section ItemPropertyTabsContent {
    
    <div id="PropertyTab_Permissions" class="PropertyTab TextNormal" style="padding: 8px;">
        
        <div style="padding: 8px;">

            <table class="PropertyTable">
        
                <thead><tr><th style="width: 125px"></th><th style="width: 250px"></th><th></th></tr></thead>
                
                <tr><td colspan="3">
                    
                    <p style="font-weight: normal; margin: 4px;">Users can belong to multiple roles. This will aggregate the available permissions 
                        
                        for the user, but a denied permssion always takes precedence. Denied permissions in any role denies the permissions for the 
                        
                        user even if explicitly granted through another role.  

                    </p> 

                </td></tr>

            </table>

        </div>

        <div style="margin: 8px;">

            <table id="PermissionsGrid"></table>

        </div>

    </div>

    <div id="PropertyTab_Membership" class="PropertyTab TextNormal" style="padding: 8px;">
        
        <div style="padding: 8px;">

            <table class="PropertyTable">
        
                <thead><tr><th style="width: 135px"></th><th style="width: 250px"></th><th></th></tr></thead>
                        
                <tr><td colspan="3">
                    
                    <p style="font-weight: normal; margin: 4px;">Adding a user to an Environment Role will grant them permissions to access that associated environment. 

                        Removing them from all roles in an Environment will remove the user from that environment. 

                    </p> 

                </td></tr>
                
                <tr>

                    <td>Security Authority: </td>

                    <td>@Html.DropDownList("Membership_SecurityAuthoritySelection", Model.SecurityAuthoritySelectList, new { style="width: 250px;", onchange="Membership_SecurityAuthoritySelection_OnChange();" })</td>

                </tr>
        
                <tr>

                    <td>User Account: </td>

                    <td>
                        
                        <div><select id="Membership_UserAccountSelection" style="width: 250px;"></select></div>

                        <div id="Membership_UserAccountSelection_ProgressBar" style="width: 248px;"></div>

                    </td>

                    <td><a id="Membership_UserAccountAdd" href="javascript:void(0);" onclick="Membership_UserAccountAdd_OnClick();">(add)</a></td>

                </tr>

            </table>

        </div>
        
        <div style="margin: 0px 8px 8px 8px;">

            <table id="MembershipGrid"></table>

        </div>

    </div>
       
}

<script type="text/javascript">

    var rolePermissionsAvailable = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.RolePermissionsAvailable));

    var roleMembership = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.Role.Membership));

    var roleMembershipBaseObject = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(new Physis.Security.RoleMembership (Model.Application)));

</script>